package kuang.juc.unsafe;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;


//同理 ConcurrentModificationException 并发修改异常
public class MapTest {
    public static void main(String[] args) {
        //Map<String, String> map = new HashMap<>();
        //Map<String, String> map = Collections.synchronizedMap(new HashMap<String, String>());
        Map<String, String> map = new  ConcurrentHashMap<String, String>();

        for (int i = 1; i < 50; i++) {
            int finalI = i;
            new Thread(()->{
                map.put(String.valueOf(finalI), UUID.randomUUID().toString().substring(0,5));
                System.out.println(map);
            },String.valueOf(i)).start();
        }
    }
}
